package com.test.qnews.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.test.qnews.R;
import com.test.qnews.adapter.DetailsImgAdapter;
import com.test.qnews.beans.NetDataBean;
import com.test.qnews.volley.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/15.
 */
public class DetailsImgActivity extends BaseActivity {
    private DetailsImgAdapter imgDetailsAdapter;
    private ViewPager viewPager;
    private TextView tvCount;
    private List<View> listViews;
    private ArrayList<NetDataBean> data;


    @Override
    protected int setLayout() {
        return R.layout.viewpager_detail_msg;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        int pos = intent.getIntExtra("pos", 0);
        data = (ArrayList<NetDataBean>) intent.getSerializableExtra("data");
        int size = data.get(pos).getImageSize();
        TextView textView = (TextView) findViewById(R.id.viewpager_title);
        textView.setText(data.get(pos).getTitle());
        viewPager = (ViewPager) findViewById(R.id.viewpager_detail_msg);

        listViews = new ArrayList<>();

        for (int i = 0; i < size; i++) {
            View view1 = LayoutInflater.from(this).inflate(R.layout.item_viewpager, null);
            NetworkImageView iv = (NetworkImageView) view1.findViewById(R.id.item_viewpager);
            tvCount = (TextView) findViewById(R.id.viewpager_count);
            tvCount.setText(i + 1 + "/" + size);
            String url = data.get(pos).getImgUrls().get(i);
            VolleySingleton.getInstance().loadImage(iv,url);
            listViews.add(view1);
        }
        imgDetailsAdapter = new DetailsImgAdapter(this, listViews);
        viewPager.setAdapter(imgDetailsAdapter);


    }


}
